using Godot;
using System;

public partial class SkillManager : Node2D
{
    [Signal]
    public delegate void OnSkillCastStartEventHandler(SkillEventEntity e);

    public static SkillManager Instance { get; private set; }

    static readonly int[] TARGET_SKILLS = { 6, 12, 13 };
    static readonly int[] NO_TARGET_SKILLS = { 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 19 };

    static bool IsTargetSkill(int id)
    {
        return Array.IndexOf(TARGET_SKILLS, id) != -1;
    }

    static bool IsNoTargetSkill(int id)
    {
        return Array.IndexOf(NO_TARGET_SKILLS, id) != -1;
    }

    public static BaseSkill CreateSkill(int id)
    {
        var md = Global.SkillModelDic[id];
        BaseSkill sk = null;
        if (IsTargetSkill(id))
        {
            sk = new TargetSkill(md);
        }
        else if (IsNoTargetSkill(id))
        {
            sk = new NoTargetSkill(md);
        }
        sk.OnCastStart += OnSkillCastStartHandler;
        return sk;
    }

    private static void OnSkillCastStartHandler(SkillEventEntity e)
    {
        Instance.EmitSignal(SignalName.OnSkillCastStart, e);
    }

    public override void _Ready()
    {
        base._Ready();
        Instance = this;
    }
}
